home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-09-07 | 5.4 KB | 152 lines | [TEXT/GEOL] |
- Item 3690442 7-Sept-89 05:35
-
- From: D2769 Comusearch, James Benson,PRT
-
- To: MACAPP.TECH$ MACAPP Tech
-
- cc: MACAPP.TEST MacApp SQA Team,APL
-
- Sub: StuffText Bug
-
-
- A while back I sent a message to MacDTS about a bug in StuffText. I thought
- the fix would make it in MacApp 2.0b9, but it didn't. So, here is a copy of
- my message, and the MacDTS reply to it.
-
- I am sending this to Macapp.Tech$ so that everybody else is able to see this
- and make the appropriate corrections to their code.
-
- Have fun everybody.
-
- Manuel Perez
-
- ============================ MY MESSAGE ============================
-
- MacDTS,
-
- I finally tracked down the problem with TEView and setting styles. I had sent
- a link a few weeks back, but seems like my description was not enough for you
- to help me out (no surprise there, since I did not know what was happening
- either).
-
- Background: I have an application that searches a text database for some
- keywords, and brings to a window sections of text (that contain the keywords).
- The text cannot be modified. It is shown using a TEView with the keywords in
- bold. If the user searches again, I StuffText the new section of text into the
- TEView. Setting styles the second time seemed to hang up the Mac. After a
- little playing around, I found out a way to fix it (and what I think is a bug).
-
- The Problem: I have repeated the problem using the DemoText application
- included in MacApp 2.0b5. Add the following two procedures inside the
- DoMenuCommand of the DemoText document. Also, add two menu items that will
- call each one of this procedures.
-
- ----------------------------------------------------------
- PROCEDURE StuffFirstText;
- VAR
- theStyle: TextStyle;
- BEGIN
- theStyle := fTEView.fTextStyle; { Get current text style }
- theStyle.tsFace := [bold]; { set face to bold }
- fTEView.SetText('This text will have the word bold in bold.');
- fTEView.SetOneStyle(37, 42, doFace, theStyle, kDontRedraw); { set style }
- { of the last word 'bold' to bold }
- SetSelect(0, 0, fTEView.fHTE); { Set insertion point at beginning }
- fTEView.RecalcText; { Recalc text }
- fTEView.ForceRedraw; { and redraw the TEView }
- END;
-
- PROCEDURE StuffSecondText;
- VAR
- theStyle: TextStyle;
- BEGIN
- theStyle := fTEView.fTextStyle; { see comments above }
- theStyle.tsFace := [bold];
- fTEView.SetText('This is some text that will be inserted and later some
- words will be made bold');
- fTEView.SetOneStyle(50, 55, doFace, theStyle, kDontRedraw);
- SetSelect(0, 0, fTEView.fHTE);
- fTEView.RecalcText;
- fTEView.ForceRedraw;
- END;
- ------------------------------------
-
- Now, compile and run the DemoText sample program. Execute the StuffFirstText
- followed by the StuffSecondText procedures. In my machine (both home II and
- work IIx), the procedure executed second will hang the Mac.
-
- Solution: If the SetOneStyle method calls were commented out, the application
- would work without any problems, so I figure the problem was with SetOneStyle.
- WRONG. The problem is caused by StuffText, but it occurs when SetOneStyle is
- called again. I have added two lines to the StuffText method that fixed the
- problem. The explanation to them seem very clear, but are basically
- speculations. What happens is, that StuffText tries to get rid of the style
- information by setting the runs[1].startChar equals to the size of the TEHandle
- + 1 (as specified by IM-V). But, it does NOT modify the nRuns or nStyles
- count. It seems like TextEdit uses those counter some place and it tries to
- access past the end of a handle (namely the styles and runs tables). So, I
- reset the nRuns and nStyles to 1 and, like magic, everything works fine.
-
-
- ------------------------------
- In TTEView.StuffText…
-
- IF fStyleType = kWithStyle THEN { Fix for styled TE. Yuk. }
- BEGIN
- styles := GetStylHandle(fHTE);
- styles^^.runs[1].startChar := SUCC(fHTE^^.teLength);
-
- { added the next two lines or else the application will hang }
- styles^^.nRuns := 1; { maybe only one is sufficient but }
- styles^^.nStyles := 1; { what the heck, better safe than sorry }
- { that’s it. map 5/23/89 }
-
- END;
-
- ----------------------------
-
- Question: Is this correct? Was that a bug, or should I have called another
- method (that I am unaware of) in my StuffxxxxText procedures?
-
- I am using MacApp 2.0b5, but I looked at 2.0b8 and the code for the relevant
- section is still the same, so I suspect that this will still happen.
-
-
- As always, thanks for your attention and support.
-
-
- Manuel A. Perez
- Software Engineer
- Compusearch Software Systems
- AppleLink: D2769
- (703) 893-7200
-
- ============================ MACDTS REPLY ============================
-
- Item 6812530 30-May-89 19:28
-
- From: SHEBANOW1 Shebanow, Andrew
-
- To: D2769 Comusearch, James Benson, PRT
-
- Sub: TEView bug
-
- To: D2769 (Manuel Perez, Compusearch)
- Subject: TEView bug
- ----------------------------------------------------------------------
- Hello,
-
- I have confirmed the bug, and passed it on to the MacApp
- engineers. Thanks for your great detective work.
-
- Have fun,
-
- Andrew Shebanow
- MacDTS
- Apple Computer, Inc.
-
- (L5/25/89.31)
-
-
-
-